package com.susallwave.srcb.controller.sys.rbac;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.susallwave.srcb.entity.sys.Role;
import com.susallwave.srcb.response.Result;
import com.susallwave.srcb.service.sys.RoleService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author MyBatisPlusGenerator
 * @since 2025-07-19
 */
@RestController
@RequestMapping("/role")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "角色管理", description = "角色管理")
public class RoleController {

    private final RoleService roleService;

    // 分页查询角色
    @GetMapping("/list")
    public Result<Page<Role>> page(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam String code,
            @RequestParam String name,
            @RequestParam String status) {
        return roleService.page(pageNum, pageSize, code, name, status);
    }

    // 新增角色
    @PostMapping("/add")
    public Result<Void> add(@RequestBody Role role) {
        return roleService.add(role);
    }

    // 修改角色
    @PostMapping("/edit")
    public Result<Void> edit(@RequestBody Role role) {
        return roleService.edit(role);
    }

    // 删除角色
    @DeleteMapping("/delete")
    public Result<String> delete(@RequestBody List<Long> ids) {
        roleService.removeByIds(ids);
        return Result.success("删除成功");
    }
}
